package com.collection.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

@Entity
public class BaseStrategy implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String fieldName;
	
	@Enumerated(EnumType.ORDINAL)
	private Strategy strategy;
	
	@Embedded
	private StrategyValue strategyValue;
	
	@OneToMany(targetEntity = FilterTag.class, cascade = CascadeType.ALL)
	@JoinColumn(name="baseStrategy_id",referencedColumnName="id")
	private List<FilterTag> filterTag;
	
	private Boolean download;
	
	private String downloadDir;
	
	private String pageStartTag;
	
	private String pageEndTag;
	
	private Integer pageNums;
	
	public enum Strategy {
		TAG,
		REGULAR,
		XPATH
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public StrategyValue getStrategyValue() {
		return strategyValue;
	}

	public void setStrategyValue(StrategyValue strategyValue) {
		this.strategyValue = strategyValue;
	}

	public List<FilterTag> getFilterTag() {
		return filterTag;
	}

	public void setFilterTag(List<FilterTag> filterTag) {
		this.filterTag = filterTag;
	}

	public Strategy getStrategy() {
		return strategy;
	}

	public void setStrategy(Strategy strategy) {
		this.strategy = strategy;
	}

	public Boolean getDownload() {
		return download;
	}

	public void setDownload(Boolean download) {
		this.download = download;
	}
	
	public String getDownloadDir() {
		return downloadDir;
	}

	public void setDownloadDir(String downloadDir) {
		this.downloadDir = downloadDir;
	}

	public String getPageStartTag() {
		return pageStartTag;
	}

	public void setPageStartTag(String pageStartTag) {
		this.pageStartTag = pageStartTag;
	}

	public String getPageEndTag() {
		return pageEndTag;
	}

	public void setPageEndTag(String pageEndTag) {
		this.pageEndTag = pageEndTag;
	}

	public Integer getPageNums() {
		return pageNums;
	}

	public void setPageNums(Integer pageNums) {
		this.pageNums = pageNums;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj != null && (obj instanceof BaseStrategy)) {
			return ((BaseStrategy) obj).getId().equals(id);
		}
		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		if (getId() == null) {
			return super.hashCode();
		} else {
			return this.getId().hashCode();
		}
	}
}
